package cn.mastor.org.controller;

import cn.mastor.basic.util.PageList;
import cn.mastor.org.domain.Sdictionarydetail;
import cn.mastor.org.query.SdictionarydetailQuery;
import cn.mastor.org.service.ISdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RequestMapping("/dictionaty")
@RestController
public class SdictionarydetailController {
    @Autowired
    private ISdictionarydetailService service;
    @GetMapping()
    public List findAll() {
        return  service.findAll();
    }
    @PostMapping
    public PageList<Sdictionarydetail> findbyPage(@RequestBody SdictionarydetailQuery query){
        return service.queryByPage(query);
    }
    @PutMapping
    public void addOrUpdate(@RequestBody Sdictionarydetail sdictionarydetail){
        if (null == sdictionarydetail.getId()){
            // 添加
            service.add(sdictionarydetail);
        }else {
            // 修改
            service.update(sdictionarydetail);
        }
    }
    @RequestMapping("/aa")
    public PageList findByid(Long id){
        List<Sdictionarydetail> departments = service.LowDeper(id);
        List byId = service.LowDeper(id);
        ArrayList<Object> list = new ArrayList<>();
        list.add(byId);
        PageList pageList = new PageList(1, departments);
        return pageList;
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Long id){
        service.delete(id);
    }
    @PatchMapping()
    public void patchdel(@RequestBody List<Long> ids) {
        service.batchDel(ids);
    }
}
